package com.aaa.controller.api;

import com.aaa.entity.Dept;
import com.aaa.entity.Notice;
import com.aaa.entity.RegisteredItem;
import com.aaa.service.RegisteredItemService;
import com.aaa.vo.NoticeVo;
import com.aaa.vo.RegisteredVo;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/api/registered")
public class RegisteredItemControllerApi {
        @Autowired
        private RegisteredItemService registeredItemService;

    //分页查询
    @PostMapping("searchReg/{currentPage}/{pageSize}")
    public Result<IPage<RegisteredItem>> searchNotice(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody RegisteredVo registeredVo){
        return registeredItemService.findByConditions(currentPage, pageSize, registeredVo);
    }

    //添加修改
    @PostMapping("saveAndUpdate")
    public Result saveAndUpdate(RegisteredItem registeredItem) {
        if (registeredItemService.saveAndUpdate(registeredItem)) {
            return new Result(200, "操作成功", true);
        } else {
            return new Result(500, "操作失败", false);
        }
    }

    //删除
    @DeleteMapping("delById/{id}")
    public Result delById(@PathVariable Long id){
        if (registeredItemService.delById(id)){
            return new Result(200,"修改成功",true);
        }else {
            return  new Result(500,"修改失败",false);
        }
    }
    //批量删除
    @PostMapping("delListById")
    public Result delListByid(@RequestBody List<RegisteredItem> registeredItemList){
        registeredItemList.forEach((RegisteredItem registeredItem)->{
            registeredItemService.removeById(registeredItem.getRegItemId());
        });
        return new Result(200,"批量删除成功",true);
    }

}
